//
//  OneTableViewCell.m
//  UI10_CustomTableViewCell
//
//  Created by dllo on 16/7/27.
//  Copyright © 2016年 yh. All rights reserved.
//

#import "OneTableViewCell.h"

@implementation OneTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // cell的默认大小(320, 44)
        // 初始化时 cell的frame是初始值 不能为自定义布局
        // 初始化方法中只负责创建
        //        NSLog(@"初始化时 cell的frame:%@", NSStringFromCGRect(self.contentView.frame));
        //        _customView = [[UIView alloc] initWithFrame:CGRectZero];
        //        _customView.backgroundColor = [UIColor cyanColor];
        
        // 创建出来的子视图添加在哪个父视图
        // contentView显示内容的
        //        [self.contentView addSubview:_customView];
        
        self.leftImageView = [[UIImageView alloc] init];
        self.leftImageView.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:self.leftImageView];
        
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.backgroundColor = [UIColor cyanColor];
        [self.contentView addSubview:self.titleLabel];
        
        
        self.contentLabel = [[UILabel alloc] init];
        // 多行显示
        self.contentLabel.numberOfLines = 0;
        [self.contentView addSubview:self.contentLabel];
        
        self.readLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.readLabel];
        
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    //    NSLog(@"%s,初始化时 cell的frame:%@", __FUNCTION__, NSStringFromCGRect(self.frame));
    //    // 坐标要用self.contentView.frame
    //    _customView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, 100);
    // 其中每个数字代表的含义 让别人好理解
    //    CGFloat leftMargin = 5;
    //    CGFloat rightMargin = 5;
    //    CGFloat topMargin = 5;
    //    CGFloat bottomMargin = 5;
    self.leftImageView.frame = CGRectMake(5, 5, 100, self.contentView.frame.size.height - 10);
    self.titleLabel.frame = CGRectMake(110, 5, self.contentView.frame.size.width - 100 - 15, self.contentView.frame.size.height / 2 - 5);
    self.contentLabel.frame = CGRectMake(110, self.contentView.frame.size.height / 2, self.contentView.frame.size.width - 100 - 15, self.contentView.frame.size.height / 2 - 5);
    // label 上不要加控件 不会显示
    self.readLabel.frame = CGRectMake(self.contentView.frame.size.width -80, self.contentView.frame.size.height - 40, 60, 30);
    // 什么时候走layoutSubviews
    // 1. 当视图添加到父视图
    // 2. 当视图大小发生变化时
    // 3. 切换横竖屏
    // 4. ScrollView滚动时
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
